<template>
  <el-dialog :title="title" :visible="state" @close="closeDia">
    <el-form :model="data">
      <el-form-item label="员工用户名" :label-width="formLabelWidth">
        <el-input v-model="data.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="员工姓名" :label-width="formLabelWidth">
        <el-input v-model="data.nickname" autocomplete="off"></el-input>
      </el-form-item>
       <el-form-item label="员工密码" :label-width="formLabelWidth">
        <el-input v-model="data.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="员工电话" :label-width="formLabelWidth">
        <el-input v-model="data.phone" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="noSure">取 消</el-button>
      <el-button type="primary" @click="sure">确 定</el-button>
    </div>
  </el-dialog>
</template>
 <script>
import * as api from "../utils/api";
export default {
  name: "ylUserDialog",
  computed: {},
  props: ["state", "title", "data"],
  data() {
    return {
      formLabelWidth: "120px",
    };
  },
  methods: {
    noSure() {
      if (this.title === "添加员工") {
        this.$emit("noCaozuo", "dialogFormVisible");
      } else {
        this.$emit("noCaozuo", "addkuang");
      }
    },
    sure() {
      console.log(this.data);
      if (this.title === "添加员工") {
        this.$emit("noCaozuo", "addkuang");
        this.axios({
          method: "post",
          url: api.ADD_USER,
          data: this.data,
        }).then((data) => {
          console.log(data);
          if (data.data.code === 200) {
            this.$emit("draw");
          }
        });
      } else {
        this.$emit("noCaozuo", "dialogFormVisible");
        this.axios({
          method: "post",
          url: api.UPDATE_USER,
          data: this.data,
        }).then((data) => {
          console.log(data);
          if (data.data.code === 200) {
             this.$emit("draw");
          }
        });
      }
    },
    closeDia() {
      if (this.title === "添加员工") {
        this.$emit("noCaozuo", "addkuang");
      } else {
        this.$emit("noCaozuo", "dialogFormVisible");
      }
    },
  },
};
</script>

<style>
</style>